1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
/*
Copyright 2009 Sebastiano Tronto <sebastiano@luganega.org>
This file is part of JBriscola.
JBriscola is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
JBriscola is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with JBriscola; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
import javax.swing.*;
public class Main {
public static int semeBriscola, punteggio, punteggioCPU, mano, cartaDaPescare;
public static boolean toccaAllaCPU = false;
public static boolean CPUHaGiocato = false;
public static boolean haGiocatoPrima = true;
public static Frame frame;
public static void main( String args[] ) {
frame = new Frame();
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setVisible( true );
frame.setResizable( false );
frame.setSize( 600, 550 );
}
public void mischia() {
mano = 0;
cartaDaPescare = 6;
ImageIcon aux;
for ( int i = 0, k = 0; i < 10; i++ )
for ( int j = 0; j < 4; j++, k++ )
frame.arrayCarteMescolate[k] = frame.arrayCarte[i][j];
for ( int i = 0; i < 391; i++ ) {
double a = Math.random() * 40;
int x = (int) a;
double b = Math.random() * 40;
int y = (int) b;
aux = frame.arrayCarteMescolate[x];
frame.arrayCarteMescolate[x] = frame.arrayCarteMescolate[y];
frame.arrayCarteMescolate[y] = aux;
}
char auxChar[] = frame.arrayCarteMescolate[39].toString().toCharArray();
semeBriscola = auxChar[auxChar.length-5] - 49;
}
public void giocaCPU() {
int cartaDaGiocare;
/*******************************************/
if ( frame.carteCPU[0] != null )
cartaDaGiocare = 0;
else if ( frame.carteCPU[1] != null )
cartaDaGiocare = 1;
else
cartaDaGiocare = 2;
/*******************************************/
frame.giocata[1] = frame.carteCPU[cartaDaGiocare];
frame.carteCPU[cartaDaGiocare] = null;
frame.pannello.repaint();
CPUHaGiocato = true;
if ( frame.giocata[0] == null )
toccaAllaCPU = false;
}
public void chiPrende() {
char aux[], auxCPU[];
aux = frame.giocata[0].toString().toCharArray();
auxCPU = frame.giocata[1].toString().toCharArray();
giocatorePrende( ( (aux[aux.length-5] - 49 == semeBriscola) && (auxCPU[auxCPU.length-5] - 49 != semeBriscola) )
|| ( (aux[aux.length-5] == auxCPU[auxCPU.length-5]) && laPrimaEPiuAlta( aux[aux.length-7] - 48, auxCPU[auxCPU.length-7] - 48 ) )
|| ( (auxCPU[auxCPU.length-5] - 49 != semeBriscola) && (aux[aux.length-5] != auxCPU[auxCPU.length-5]) && haGiocatoPrima ) );
}
public boolean laPrimaEPiuAlta( int prima, int seconda ) {
int a, b;
switch ( prima ) {
case 0:
a = 10;
break;
case 1:
a = 12;
break;
case 3:
a = 11;
break;
default:
a = prima;
break;
}
switch ( seconda ) {
case 0:
b = 10;
break;
case 1:
b = 12;
break;
case 3:
b = 11;
break;
default:
b = seconda;
break;
}
return a > b;
}
public void giocatorePrende( boolean giocatore ) {
if ( giocatore ) {
toccaAllaCPU = CPUHaGiocato = false;
haGiocatoPrima = true;
}
else {
toccaAllaCPU = true;
CPUHaGiocato = haGiocatoPrima = false;
}
daiPunti( giocatore );
if ( toccaAllaCPU )
giocaCPU();
}
public void daiPunti( boolean giocatore ) {
char aux[], auxCPU[];
aux = frame.giocata[0].toString().toCharArray();
auxCPU = frame.giocata[1].toString().toCharArray();
int punti = 0;
switch( aux[aux.length-7] - 48 ) {
case 0:
punti += 4;
break;
case 1:
punti += 11;
break;
case 3:
punti += 10;
break;
case 8:
punti += 2;
break;
case 9:
punti += 3;
break;
default:
break;
}
switch( auxCPU[auxCPU.length-7] - 48 ) {
case 0:
punti += 4;
break;
case 1:
punti += 11;
break;
case 3:
punti += 10;
break;
case 8:
punti += 2;
break;
case 9:
punti += 3;
break;
default:
break;
}
frame.giocata[0] = frame.giocata[1] = null;
if ( giocatore ) {
punteggio += punti;
if ( mano < 18 ) {
if ( frame.carteInMano[0] == null )
frame.carteInMano[0] = frame.arrayCarteMescolate[cartaDaPescare];
if ( frame.carteInMano[1] == null )
frame.carteInMano[1] = frame.arrayCarteMescolate[cartaDaPescare];
if ( frame.carteInMano[2] == null )
frame.carteInMano[2] = frame.arrayCarteMescolate[cartaDaPescare];
cartaDaPescare++;
if ( frame.carteCPU[0] == null )
frame.carteCPU[0] = frame.arrayCarteMescolate[cartaDaPescare];
if ( frame.carteCPU[1] == null )
frame.carteCPU[1] = frame.arrayCarteMescolate[cartaDaPescare];
if ( frame.carteCPU[2] == null )
frame.carteCPU[2] = frame.arrayCarteMescolate[cartaDaPescare];
cartaDaPescare++;
}
}
else {
punteggioCPU += punti;
if ( mano < 18 ) {
if ( frame.carteCPU[0] == null )
frame.carteCPU[0] = frame.arrayCarteMescolate[cartaDaPescare];
if ( frame.carteCPU[1] == null )
frame.carteCPU[1] = frame.arrayCarteMescolate[cartaDaPescare];
if ( frame.carteCPU[2] == null )
frame.carteCPU[2] = frame.arrayCarteMescolate[cartaDaPescare];
cartaDaPescare++;
if ( frame.carteInMano[0] == null )
frame.carteInMano[0] = frame.arrayCarteMescolate[cartaDaPescare];
if ( frame.carteInMano[1] == null )
frame.carteInMano[1] = frame.arrayCarteMescolate[cartaDaPescare];
if ( frame.carteInMano[2] == null )
frame.carteInMano[2] = frame.arrayCarteMescolate[cartaDaPescare];
cartaDaPescare++;
}
}
frame.pannello.repaint();
frame.repaint();
}
}
|